import 'package:flutter/material.dart';
import 'package:flutter_base/config/app_color.dart';
import 'package:flutter_base/config/app_config.dart';
import 'package:flutter_base/config/app_routes.dart';
import 'package:flutter_base/widgets/appbar/common_app_bar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_base/base/widget/base_get_builder.dart';
import 'package:flutter_base/widgets/button/common_button.dart';
import 'package:flutter_base/generated/assets.dart';
import 'package:flutter_base/widgets/image/auto_image.dart';
import 'package:flutter_base/widgets/image/image_view.dart';
import 'register_success_logic.dart';

class RegisterSuccessPage extends StatelessWidget {
  final logic = Get.put(RegisterSuccessLogic());

  RegisterSuccessPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PopScope(
        canPop: false,
        child: BaseGetBuilder<RegisterSuccessLogic>(
          backgroundColor: AppColor.colorF5F7FA,
          appBar: CommonAppBar(
            title: '',
            onLeftClick: () {
              logic.goToLogin();
            },
          ),
          extendBodyBehindAppBar: true,
          builder: (_) {
            return Stack(
              children: [
                // 背景图
                const Positioned.fill(
                  child: AutoImage(
                    Assets.accountBg,
                    fit: BoxFit.fitWidth,
                    alignment: Alignment.topCenter,
                  ),
                ),

                SafeArea(
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: 24.w),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        24.verticalSpaceFromWidth,
                        _buildSuccessIcon(),
                        // const Spacer(),
                        20.verticalSpaceFromWidth,
                        _buildSuccessMessage(),
                        SizedBox(height: 24.w),
                        _buildLoginButton(),
                        SizedBox(height: 48.w),
                      ],
                    ),
                  ),
                ),
              ],
            );
          },
        ));
  }

  Widget _buildSuccessIcon() {
    return Center(
      child: AutoImage(
        logic.type == 'reset' ? Assets.resetSuccess : Assets.registerSuccess,
        width: 100.w,
        height: 100.w,
        fit: BoxFit.cover,
      ),
    );
  }

  Widget _buildSuccessMessage() {
    return Column(
      children: [
        Text(
          logic.type == 'reset'
              ? "Password set successfully"
              : 'Registration successful',
          style: TextStyle(
            fontSize: 24.sp,
            fontWeight: FontWeight.w600,
            color: AppColor.color0C0A09,
          ),
          textAlign: TextAlign.center,
        ),
        SizedBox(height: 8.w),
        Text(
          'Go to login now',
          style: TextStyle(
            fontSize: 12.sp,
            fontWeight: FontWeight.w400,
            color: const Color(0xFFB7B7B7),
          ),
          textAlign: TextAlign.center,
        ),
      ],
    );
  }

  Widget _buildLoginButton() {
    return CommonButton.expend(
      title: 'Go to login',
      type: ButtonType.primary,
      onClick: () => logic.goToLogin(),
    );
  }
}
